<%@ tag language="java" pageEncoding="UTF-8" %>  
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://www.springframework.org/tags" prefix="s"%>
<c:set var="contextPath" value="${pageContext.request.contextPath}"/>
<%@ attribute name="recordId" required="true" rtexprvalue="true"%>
<%@ attribute name="moduleCode" required="true" rtexprvalue="true"%>

<div id="opLogPanel"  ng-controller="OpLogCtrl">   
 <p><button type="button" class="btn" ng-click="reloadLogs();"><i class="icon-refresh"></i> <s:message code="btn.refresh"/></button></p>                            
  
  <div class="media" style="border-bottom: 1px dashed #EAEAEA;" ng-repeat="row in opLogs" id="opLogRow{{$index}}">
    <a class="pull-left" href="#">
      <img class="user-photo" ng-src="${contextPath }/upload/avatar/avatar.gif"  ng-if="!row.opUserAvatar">
      <img class="user-photo" ng-src="${contextPath }/upload/avatar/{{row.opUserAvatar}}_2.jpg"  ng-if="row.opUserAvatar" onerror="onerror=null;this.src='${contextPath }/upload/avatar/avatar.gif'">
    </a>
    <div class="media-body">
      <p class="media-heading">{{row.opUsername}}&nbsp;<b>{{row.action}}</b>&nbsp;&nbsp;<span data-ng-bind-html="row.opContent"></span></p>
      <p class="op-comment" ng-if="row.opComment">{{row.opComment}}</p>
      <p>{{row.opDatetime | date:"yyyy-MM-dd HH:mm:ss"}}</p>
    </div>
  </div>  
    
</div>

<script type="text/javascript">

function OpLogCtrl($scope, $http, $sce) {
  $scope.opLogs = [];
  $scope.formData = {};
  
  //init
  $http.get('${contextPath}/system/userOpLog/getLogs.json?moduleCode=${moduleCode}&recordId=${recordId}', {
  }).success(function(data) {
      $scope.opLogs = angular.forEach(data.userOpLogs, function (opLog) {
        opLog.opContent = $sce.trustAsHtml(opLog.opContent);
      });
  }); 
  
  $scope.reloadLogs = function(){
    $http.get('${contextPath}/system/userOpLog/getLogs.json?moduleCode=${moduleCode}&recordId=${recordId}', {
    }).success(function(data) {    
        $scope.opLogs = angular.forEach(data.userOpLogs, function (opLog) {
          opLog.opContent = $sce.trustAsHtml(opLog.opContent);
        });
    }); 
  }
}
</script> 